package thread;

public class demo10 {
    public static  boolean isquit = false;
    public static void main(String[] args) {
        Thread t = new Thread(() -> {
            while(!isquit){
                System.out.println("hello Thread");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });
        t.start();
        //只要把这个isquit设置为true，进一步的run就执行完了，再进一步就是线程执行结束了。
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        isquit = true;
        System.out.println("终止线程！");
    }
}
